﻿using Framework.Resource;
using UnityEngine;

namespace Framework.Procedure
{

    public class ProcedureUpdateResourceVersion : ProcedureBase
    {
        private bool updataFinish;
        private bool needDown;
        public override void Enter(IProcedureOwner procedureOwner)
        {
            base.Enter(procedureOwner);
            updataFinish = false;
            GameEntry.GetComponent<ResourceManager>().UpdateResourceVersion((result,needDown) =>
            {
                updataFinish = result;
                this.needDown = needDown;
                Debug.Log("更新完成"+ (needDown ? " " : "不")+"需要更新");
            });
        }

        public override void Update(IProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
        {
            base.Update(procedureOwner, elapseSeconds, realElapseSeconds);
            if (updataFinish)
            {
                if (needDown)
                {
                    procedureOwner.ChangeState<ProcedureDownloadResource>();
                }
                else
                {
                    procedureOwner.ChangeState<ProcedureConfigInit>();
                }
                
            }
        }
    }

}